package utils;

import mybatis.cfg.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;

public class DateSourceUtil {
  /**
   * 根据Configuration对象创建并返回Connection对象
   * @param cfg
   * @return
   */
  public static Connection getConnection(Configuration cfg) {
    try {
      Class.forName(cfg.getDriver());
      return DriverManager.getConnection(cfg.getUrl(), cfg.getUsername(), cfg.getPassword());
    } catch (Exception e) {
      throw new RuntimeException("Configuration中连接数据库错误");
    }
  }
}
